<?php
/***********************************************************************
 * @package    IvanEngine
 * @subpackage Core
 * @author     Ivan <ivanzx@msn.com>
 * @created    2010-05-13
 ***********************************************************************/
if(defined("IVANENGINE_CORE_STL_ITERATOR"))
	die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("IVANENGINE_CORE_STL_ITERATOR", true);

require_once (dirname(__FILE__).'/../Base.php');

class CIterator extends CBase
{
	protected $m_object	= null;
	protected $m_where	= -1;
	
	public function __construct(CArray & $object, $where)
	{
		parent::__construct();
		$this->m_object	= $object;
		$this->m_where	= $where;
	}
	
	public function __destruct()
	{
		unset($this->m_object);
		parent::__destruct();
	}
	
	public function Pos()
	{
		return $this->m_where;
	}
	
	public function & Value()
	{
		return $this->m_object->Get($this->m_where);
	}
	
	public function Next()
	{
		if( $this->m_where < $this->m_object->Size() + 1 )
		{
			$this->m_where += 1;
			return true;
		}else{
			return false;
		}
	}
	
	public function Rewind()
	{
		if( $this->m_where > 0 )
		{
			$this->m_where = 0;
			return true;
		}else{
			return false;
		}
	}
	
	public function Begin()
	{
		$this->m_where 	= 0;
	}
	
	public function End()
	{
		$this->m_where 	= $this->m_object->Size() - 1;
	}
	
	public function IsEnd()
	{
		return $this->m_where == $this->m_object->Size();
	}
	
	public function IsBegin()
	{
		return $this->m_where == 0;
	}
	
	public function IsValid()
	{
        if( !$this->m_object ){
            return false;
        }
		return $this->m_where >= 0 && $this->m_where < $this->m_object->Size();
	}
}


?>